package com.chukun.inventory.web;

import com.alibaba.fastjson.JSON;
import com.chukun.inventory.model.User;
import com.chukun.inventory.service.UserService;
import com.chukun.inventory.vo.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chukun
 * @version 1.0.0
 * @description 用户服务接口
 * @createTime 2022年04月05日 20:59:00
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/getUserInfo")
    @ResponseBody
    public ResponseData getUserInfo() {
        List<User> users = userService.getUserInfo();
        ResponseData responseData = new ResponseData(ResponseData.SUCCESS);
        if (CollectionUtils.isEmpty(users)) {
            responseData.setData(JSON.toJSONString(new ArrayList<>()));
            return responseData;
        }
        String retJson = JSON.toJSONString(users);
        responseData.setData(retJson);
        return responseData;
    }
}
